package com.example.wanbaqian.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.wanbaqian.R;
import com.example.wanbaqian.base.BaseActivity;
import com.example.wanbaqian.config.CommonValue;
import com.example.wanbaqian.base.HttpCallback;
import com.example.wanbaqian.config.HttpURL;
import com.example.wanbaqian.bean.Info;
import com.example.wanbaqian.utils.GetJsonUtils;
import com.example.wanbaqian.utils.HttpUtils;
import com.example.wanbaqian.utils.JsonUtils;
import com.example.wanbaqian.utils.SPUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 收益钱包
 */
public class WalletActivity extends BaseActivity implements HttpCallback {
    @BindView(R.id.wallet_sumMoney)
    TextView walletSumMoney;

    @Override
    protected int getLayout() {
        return R.layout.activity_wallet;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setStatusBarColor(R.color.colorBackground);
        setToolBar("收益钱包");
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        toolBar_tvRight.setVisibility(View.VISIBLE);
        toolBar_tvRight.setText("明细");
    }

    @Override
    protected void initDate() {
        HttpUtils.getInstance().post(GetJsonUtils.getInstance().getRequest(HttpURL.CASH_OVERVIEW, mContext, new String[]{"accessid"},
                new String[]{SPUtils.getAccessid(mContext)}), mContext, null, CommonValue.REQUEST_CODE1, this);
    }

    @OnClick({R.id.toolBar_tvRight, R.id.wallet_tx})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.toolBar_tvRight:
                openActivity(WalletDetailedActivity.class);
                break;
            case R.id.wallet_tx:
                HttpUtils.getInstance().post(GetJsonUtils.getInstance().getRequest(HttpURL.WITHDRAW_BANK, mContext,
                        new String[]{"accessid"}, new Object[]{SPUtils.getAccessid(mContext)}),mContext, null, CommonValue.REQUEST_CODE2, this);
                break;
        }
    }

    @Override
    public void onSuccess(String content, Info info, int requestCode) {
        switch (requestCode) {
            case CommonValue.REQUEST_CODE1:
                walletSumMoney.setText(Double.parseDouble(JsonUtils.getInstance().getJsonObject(content, "account_balance")) + "元");
                break;
            case CommonValue.REQUEST_CODE2:
                Bundle bundle = new Bundle();
                bundle.putString("bank_info", content);
                bundle.putString("money", walletSumMoney.getText().toString());
                openActivity(FindWithDrawalActivity.class, bundle);
                break;
        }
    }

    @Override
    public void onCacheSuccess(String content, Info info, int requestCode) {

    }

    @Override
    public void onError(Info info, int requestCode) {
        showToast(info.getMsg());
    }
}
